#define YELLOW D7 #define WHITE D6 #define BLUE D5 #define RED D8 #define time 100 #define BUTTON D4 // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(YELLOW, OUTPUT); pinMode(WHITE, OUTPUT); pinMode(BLUE, OUTPUT); pinMode(RED, OUTPUT); pinMode(BUTTON, INPUT_PULLDOWN); } // the loop function runs over and over again forever void loop() { if (digitalRead(BUTTON)==HIGH) { chase_4(); //Made a separate function chase_4 to better organize //To set the condition: if pulldown is used, set the condition to high. if pullup is used, set it to low } else { digitalWrite(YELLOW, LOW); // turn the LED on (HIGH is the voltage level) digitalWrite(WHITE, LOW); // turn the LED off by making the voltage LOW digitalWrite(BLUE, LOW); // turn the LED on (HIGH is the voltage level) digitalWrite(RED, LOW); // turn the LED on (HIGH is the voltage level) } } // to run the leds as a ring void chase_4() { digitalWrite(YELLOW, HIGH); // turn the LED on (HIGH is the voltage level) digitalWrite(WHITE, LOW); // turn the LED off by making the voltage LOW digitalWrite(BLUE, LOW); // turn the LED on (HIGH is the voltage level) digitalWrite(RED, LOW); // turn the LED on (HIGH is the voltage level) delay(time); digitalWrite(YELLOW, LOW); // turn the LED on (HIGH is the voltage level) digitalWrite(WHITE, HIGH); // turn the LED off by making the voltage LOW digitalWrite(BLUE, LOW); // turn the LED on (HIGH is the voltage level) digitalWrite(RED, LOW); // turn the LED on (HIGH is the voltage level) delay(time); // wait for a second digitalWrite(WHITE, LOW); // turn the LED off by making the voltage LOW digitalWrite(BLUE, HIGH); // turn the LED on (HIGH is the voltage level) digitalWrite(YELLOW, LOW); // turn the LED on (HIGH is the voltage level) digitalWrite(RED, LOW); // turn the LED on (HIGH is the voltage level) delay(time); digitalWrite(WHITE, LOW); // turn the LED off by making the voltage LOW digitalWrite(RED, HIGH); // turn the LED on (HIGH is the voltage level) digitalWrite(BLUE, HIGH); // turn the LED on (HIGH is the voltage level) digitalWrite(YELLOW, LOW); // turn the LED on (HIGH is the voltage level) delay(time); }